package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.MarketStorage;
import com.cskaoyan.model.admin.vo.BaseRespVo;
import com.cskaoyan.service.admin.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * @author hanshuai
 * @version 1.0
 * @description @TODO
 * @date 2021/12/2 11:49
 */
@RestController
@RequestMapping("wx/storage")
public class WxStorageController {
    @Autowired
    StorageService storageService;

    @RequestMapping("upload")
    public BaseRespVo adminCreate(MultipartFile file) throws IOException {
        UUID uuid = UUID.randomUUID();
        String originalFilename = file.getOriginalFilename();
        UUID code = uuid;
        file.transferTo(new File("d:/wx/storage/fetch/", uuid + originalFilename.substring(originalFilename.length() - 4)));
        MarketStorage marketStorage = storageService.storeAvatar(file, code);
        return BaseRespVo.ok(marketStorage);
    }
}
